package com.luzhikun.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
 * @Author liu-miss
 * @Description 改变所有请求响应字符集
 * @Date 23:08 2021/5/23
 **/
public class CharSetFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {

        HttpServletRequest request= (HttpServletRequest) req;
        request.setCharacterEncoding("UTF-8");
        HttpServletResponse response= (HttpServletResponse) resp;
        chain.doFilter(req, resp);
        response.setContentType("text/html;charset=UTF-8");
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
